package com.ruoyi.activity.service.impl;

import java.util.List;

import com.ruoyi.activity.mapper.TbUserCouponMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.activity.mapper.TbMerchantMapper;
import com.ruoyi.activity.domain.TbMerchant;
import com.ruoyi.activity.service.ITbMerchantService;

import javax.annotation.Resource;

/**
 * 商家Service业务层处理
 * 
 * @author jll
 * @date 2025-06-13
 */
@Service
public class TbMerchantServiceImpl implements ITbMerchantService 
{
    @Autowired
    private TbMerchantMapper tbMerchantMapper;

    @Resource
    private TbUserCouponMapper tbUserCouponMapper;

    /**
     * 查询商家
     * 
     * @param id 商家主键
     * @return 商家
     */
    @Override
    public TbMerchant selectTbMerchantById(Long id)
    {
        return tbMerchantMapper.selectTbMerchantById(id);
    }

    /**
     * 查询商家列表
     * 
     * @param tbMerchant 商家
     * @return 商家
     */
    @Override
    public List<TbMerchant> selectTbMerchantList(TbMerchant tbMerchant)
    {
        List<TbMerchant> tbMerchants = tbMerchantMapper.selectTbMerchantList(tbMerchant);
        for (TbMerchant merchant : tbMerchants) {
            merchant.setCancelNumber(tbUserCouponMapper.selectTbUserCouponCancel(merchant.getId(), null));
        }
        return tbMerchants;
    }

    /**
     * 新增商家
     * 
     * @param tbMerchant 商家
     * @return 结果
     */
    @Override
    public int insertTbMerchant(TbMerchant tbMerchant)
    {
        tbMerchant.setCreateTime(DateUtils.getNowDate());
        return tbMerchantMapper.insertTbMerchant(tbMerchant);
    }

    /**
     * 修改商家
     * 
     * @param tbMerchant 商家
     * @return 结果
     */
    @Override
    public int updateTbMerchant(TbMerchant tbMerchant)
    {
        tbMerchant.setUpdateTime(DateUtils.getNowDate());
        return tbMerchantMapper.updateTbMerchant(tbMerchant);
    }

    /**
     * 批量删除商家
     * 
     * @param ids 需要删除的商家主键
     * @return 结果
     */
    @Override
    public int deleteTbMerchantByIds(Long[] ids)
    {
        return tbMerchantMapper.deleteTbMerchantByIds(ids);
    }

    /**
     * 删除商家信息
     * 
     * @param id 商家主键
     * @return 结果
     */
    @Override
    public int deleteTbMerchantById(Long id)
    {
        return tbMerchantMapper.deleteTbMerchantById(id);
    }
}
